// import path from 'path'
import { createRouter, createWebHistory } from 'vue-router'

const routess:any=[
  {
    path:'/home/index',
    name:'index',
    component:()=>import('../views/home/index.vue'),
    title:'首页系统',
    meta:{title:'首页系统'}
  },
  {
    path:'/home/auth',
    name:'auth',
    component:()=>import('../views/home/auth.vue'),
    title:'系统菜单',
    meta:{title:'系统菜单'}
  },
   {
    path:'/home/menu',
    name:'menu',
    component:()=>import('../views/home/menu.vue'),
    title:'菜单系统',
    meta:{title:'菜单系统'}
  },
   {
    path:'/home/user',
    name:'user',
    component:()=>import('../views/home/user.vue'),
    title:'用户中心',
    meta:{title:'用户中心'}
  },
  {
    path:'/home/menuios',
    name:'menuios',
    component:()=>import('../views/home/menuios.vue'),
    title:'地图',
    meta:{title:'地图'}
  },
  {
    path:'/home/userioms',
    name:'userioms',
    component:()=>import('../views/home/userioms.vue'),
    title:'用户列表',
    meta:{title:'用户列表'}
  }
]
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
       path:'/',
       redirect:'login'
    },
    {
      path: '/login',
      name: 'login',
      component:()=>import('../views/login.vue')
    },
    {
      path:'/home',
      name:'home',
      component:()=>import('../views/home.vue'),
      children:routess,
      meta:{title:'首页'}
    }
  ]
})
router.beforeEach((to, from, next) => {
   if(to.path==='/login')return next()
    if(localStorage.getItem('token')!=null){
      return next()
    }else{
      return next({name:'login'})
    }
});
export default router
